package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface OrderMapper extends BaseMapper<Order> {

    @Select("select count(1) from t_order where SETMEAL_ID=#{sId} and MEMBER_ID=#{mId} and ORDERDATE=#{orderDate} ")
    int findOrderBySetmealIdAndOrderDateAndMemberId(@Param("sId") Integer sId, @Param("mId") Integer mId, @Param("orderDate") String orderDate);

    @Select("select setmeal_id,member_id,orderdate,ordertype from t_order where id=#{id}")
    Order selectOrderInfoByOrderId(@Param("id") Integer id);


    //报表数据 todoby dzf

    @Select("select count(1) from t_order where ORDERDATE = current_date")
    Integer getDayReservations();


    @Select("select count(1) from t_order tor,rpt_date rd where DATE_FORMAT(current_date,'%m') = rd.fmonth " +
            "  and tor.ORDERDATE = rd.fdate " +
            "  and DATE_FORMAT(current_date,'%Y') = rd.fyear")
    Integer getMonthReservations();


    @Select("select count(1) from t_order tor,rpt_date rd where DATE_FORMAT(current_date,'%u') = rd.fweek " +
            " and tor.ORDERDATE= rd.fdate and DATE_FORMAT(current_date,'%Y') = rd.fyear")
    Integer getWeekReservations();


    @Select("select count(1) from t_order where ORDERDATE = current_date and ORDERSTATUS = '已到珍'")
    Integer getFinishDay();


    @Select("select count(1) from t_order tor,rpt_date rd where DATE_FORMAT(current_date,'%u') = rd.fweek " +
            "and tor.ORDERDATE= rd.fdate and DATE_FORMAT(current_date,'%Y') = rd.fyear and tor.ORDERSTATUS = '已到珍'")
    Integer getFinishWeek();


    @Select("select count(1) from t_order tor,rpt_date rd where DATE_FORMAT(current_date,'%m') = rd.fmonth\n" +
            "and tor.ORDERDATE = rd.fdate\n" +
            "and DATE_FORMAT(current_date,'%Y') = rd.fyear and tor.ORDERSTATUS = '已到珍'")
    Integer getFinishMonth();


    @Update("update t_order set paid = 1 where id = #{orderId}")
    void updateByOrderId(@Param("orderId") Integer orderId);


    @Select("select paid from t_order where id = #{id}")
    Integer findState(@Param("id")Integer id);
}
